<?php // $Id: common.php 11 2008-07-30 15:46:18Z the.sk89q $

/**
 * common.php - common functions
 *
 * @version: $Id: common.php 11 2008-07-30 15:46:18Z the.sk89q $
 * @license http://www.gnu.org/copyleft/gpl.html
 * @package dpmatchreserve
 * 
 */

$base_dir = dirname(__FILE__);

if (!file_exists("./config.php")) {
    echo "Error: It looks like that this application has not been properly installed. The configuration file is missing.";
    exit;
}

require "./config.php";
require "include/Smarty/Smarty.class.php";

if (count($CONFIG['servers']) == 0) {
    echo "Error: It looks like that this application has not been properly installed. There are no servers configured.";
    exit;
}

if (!is_writable("cache")) {
    echo "Error: It looks like that this application has not been properly installed. The cache directory cannot be written to.";
    exit;
}

// Automatically guess base URL
if (empty($CONFIG['base_url'])) {
    $CONFIG['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].($_SERVER['SERVER_PORT'] != 80 ? ":{$_SERVER['SERVER_PORT']}" : '').dirname($_SERVER['SCRIPT_NAME']);
}

// Load up templateing engine
$smarty = new Smarty();

$smarty->debugging = $CONFIG['theme_debug_console'] ? true : false;
$smarty->compile_check = $CONFIG['theme_debug'] ? true : false;

$smarty->template_dir = "$base_dir/themes/{$CONFIG['theme']}";
$smarty->compile_dir = "$base_dir/cache/templates/compile";
$smarty->cache_dir = "$base_dir/cache/templates";
$smarty->config_dir = "$base_dir/themes/{$CONFIG['theme']}";

$smarty->assign('theme_url', "themes/{$CONFIG['theme']}");

function show_fatal_error($error)
{
    global $smarty;
    
    $smarty->assign('errors', array($error));
    $smarty->display('error.tpl');
    exit;
}
